
<template>
  <base-breadcrumb>
    <!-- 搜索 -->
    <searchData :searchData="searchArr" @search="search"></searchData>
    <a-card>
      <!-- <title-name title="策划执行书列表" /> -->
      <a-alert class="mb12" type="info" show-icon>
        <template slot="message">
          共计<a
            >&nbsp;<b>{{ total }}</b></a
          >&nbsp;个</template
        >
      </a-alert>
      <list-table ref="table" row-key="id" :columns="columns" :request="loadData" :alert="true" show-size-changer show-quick-jumper >
        <template slot="version" slot-scope="text, record">
          <span v-if="text < 1">--</span>
          <a v-else @click="handleVersionRecord(record)">
            V
            {{ text }}
          </a>
        </template>
        <template slot="status" slot-scope="text">
           <span v-if="text*1===0">待提交</span>
           <span v-if="text*1===1">已提交</span>
           <span v-if="text*1===2">审核中</span>
           <span v-if="text*1===3">审核不通过</span>
           <span v-if="text*1===4">审核通过</span>
           <!-- <span>{{text*1===0?'待提交':'已提交'}}</span> -->
        </template>
        <template slot="operation" slot-scope="text, record">
          <MoreButton>
            <a v-btnPermission="[{code:'seex_pm_052_loo_01',ident:'prma_seex'},{code:'buco_pm_052_loo_01',ident:'prma_buco'}]" @click="handleOperation('detail', record)">查看</a>
            <template v-if="record.isEditButton*1===1 && hideBuquBtn()">
               <a v-btnPermission="[{code:'seex_pm_052_edi_02',ident:'prma_seex'},{code:'buco_pm_052_edi_02',ident:'prma_buco'}]" v-if="record.status === 0 || record.status === 3" @click="handleOperation('update', record)">编辑</a>
               <a v-btnPermission="[{code:'seex_pm_052_gxi_03',ident:'prma_seex'},{code:'buco_pm_052_gxi_03',ident:'prma_buco'}]" v-if="record.status === 1 || record.status === 4" @click="handleOperation('change', record)">更新</a>
            </template>
            <a v-if="record.reviewButton == 1" @click="$bus.$emit('showApprovalDetailsDialog', record.id)">审批信息</a>
          </MoreButton>
        </template>
      </list-table>
    </a-card>
    <!-- 版本记录 -->
    <VersionRecord :visible.sync="versionVisible" :data="versionData" />
    <!-- 版本记录 -->
  </base-breadcrumb>
</template>
<script>
import { typeList, pageName, pageNames } from './model'
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import OrgTreeSelect from '@/components/OrgTreeSelect'
import MoreButton from '@/components/MoreButton'
import VersionRecord from './components/VersionRecord'
import { getPageSchemeDetailBySearch } from '@/api/project/plannManagement/index.js' // api
const searchArr = [
  // 搜索框
  // { name: '所属分公司', valueKey: 'branchComId', type: SelectSubCompany },
  // { name: '所属项目', keyValue: 'branchComId', valueKey: 'projectId', type: SelectProject },
  { name: '所属单位', valueKey: 'searchQuery', type: OrgTreeSelect },
  { name: '工程策划名称',type: 'input', value: 'schemeName'},
  {
    name: '创建时间',
    type: 'dateRange',
    value: 'modifiedTime',
    attr: {
      rangeFormat: ['createStartTime', 'createEndTime']
    }
  },
  { name: '状态', value: 'status', type: 'select', data: typeList }
]
const columns = [
  { title: '所属项目', dataIndex: 'projectName', ellipsis: true, align: 'center'},
  { title: '所属分公司', dataIndex: 'branchComName', ellipsis: true,align: 'center'},
  { title: '工程策划名称', dataIndex: 'schemeName', ellipsis: true,align: 'center'},
  { title: '创建时间', dataIndex: 'createTime', ellipsis: true,align: 'center'},
  { title: '填写人', dataIndex: 'fillName',ellipsis: true,align: 'center'},
  { title: '填报时间', dataIndex: 'fillTime', ellipsis: true,align: 'center'},
  { title: '版本', dataIndex: 'version', ellipsis: true,scopedSlots: { customRender: 'version' },align: 'center'},
  { title: '状态', dataIndex: 'status', scopedSlots: { customRender: 'status' },align: 'center'},
  { title: '操作', dataIndex: 'operation',align: 'center', scopedSlots: { customRender: 'operation' }}
]
export default {
  name: 'plannTableIndex',
  components: {
    SelectSubCompany,
    SelectProject,
    MoreButton,
    VersionRecord,
    OrgTreeSelect
  },
  data() {
    return {
      // 搜索选项
      searchArr,
      total:0,
      // 表头
      columns,
      // 版本记录显示隐藏
      versionVisible: false,
      queryParam:{},
      // 版本记录信息
      versionData: {},
      loadData: async (parameter) => {
        parameter.pageNum = parameter.pageNo;
        delete parameter.pageNo
        const requestParameters = Object.assign({}, parameter, { param: this.queryParam})
        return getPageSchemeDetailBySearch(requestParameters).then((res) => {
            this.total = res.totalSize || 0
            return res

        })
      }
    }
  },
  mounted(){
    console.log(1111111)
  },
  methods: {
    // 搜索
    search(value) {
      value && (this.queryParam = value)
      this.$refs.table.refresh(true)
    },
    handleOperation(pageType, record) {
      const { id, code } = record
      this.$router.push({
        path: '/project/plannManagement/plannTableComponents',
        query: {
          id,
          pageType,
          editModel: pageType == 'detail' ? 0 : 1,
          pageName: pageName[code - 26]
        }
      })
    },
    handleVersionRecord(record){
      this.versionVisible = true
      this.versionData = record
    }
  }
}
</script>
<style lang="less" scoped>
</style>
